
package com.joysuch.wwyt.edu.enums;

public enum VideoTypes {

    tcp("1", "TCP"),
    MULTI_CHOICE("2", "UDP");

    private String code;
    private String name;

    private VideoTypes(String code, String name) {
        this.code = code;
        this.name = name;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getName() {
        return name;
    }

    public boolean is(String code) {
        return this.code.equals(code);
    }

    public static VideoTypes findByName(String name) {
        VideoTypes[] values = VideoTypes.values();
        for (VideoTypes v : values) {
            if (v.getName().equals(name)) {
                return v;
            }
        }
        return null;
    }

    public static VideoTypes findByCode(String code) {
        VideoTypes[] values = VideoTypes.values();
        for (VideoTypes v : values) {
            if (v.getCode().equals(code)) {
                return v;
            }
        }
        return null;
    }

    public static String findNameByCode(String code) {
        VideoTypes types = findByCode(code);
        return types == null ? null : types.name;
    }

    public static String findCodeByName(String name) {
        VideoTypes types = findByName(name);
        return types == null ? null : types.code;
    }
}
